package ProducerConsumer;

import java.util.concurrent.BlockingQueue;

/**
 * 使用阻塞队列实现一个简单的生产者-消费者
 */
public class Producer implements Runnable{
    private BlockingQueue<String> queue;
    public Producer(BlockingQueue<String> queue){
        this.queue = queue;
    }

    @Override
    public void run() {
        int i = 0;
        while (i < 50){
            i++;
            try {
                queue.put("第"+i+"个值");
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
